# -* - coding: UTF-8 -* -
#import sys
#reload(sys)
#sys.setdefaultencoding('utf8')

import string
import logging
import json

#执行定义的任务
class CommandTask():  
	def __init__(self,commander,action,data):  
		self.commander=commander
		self.action=action
		self.data=data
		
	def execute(self):
		if hasattr(self.commander, action):
			func = getattr(self.commander, action)		#根据函数名获得函数
			if func:
				try:
					response=func(self.data)
					return response
				except Exception as e:
					logging.error('CommandTask.execute')
					logging.exception(e)
					time.sleep(0.1)		